<!-- 车型管理 -->
<template>
  <div class="dashboard-container car-models customer-list-box">
    <!-- 搜索区域 -->
    <div class="box">
      <el-form
        label-width="120px"
        style="margin-right: 40px;"
      >

        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="车型编号：">
              <el-input
                v-model.trim="formTabe.id"
                placeholder="请输入车型编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应载重量：">
              <el-select
                v-model="formTabe.allowableLoad"
                placeholder="请选择应载重量"
              >
                <el-option
                  v-for="item in allowableLoad"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应载体积：">
              <el-select
                v-model="formTabe.allowableVolume"
                placeholder="请选择应载体积"
              >
                <el-option
                  v-for="item in allowableVolume"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="车辆类型：">
              <el-input
                v-model.trim="formTabe.name"
                placeholder="请输入车辆类型"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col
            :span="6"
            :offset="1"
          >
            <div>
              <el-button
                type="danger"
                @click="search"
              >搜索</el-button>
              <el-button @click="reset">重置</el-button>
            </div>

          </el-col>
        </el-row>

      </el-form>

    </div>

    <!-- 表格区域 -->
    <div
      v-loading="loading"
      element-loading-text="加载中"
      class="table"
    >

      <el-button
        type="danger"
        style="margin-bottom: 30px; width: 120px;"
        @click="addCarType"
      >新增车型</el-button>

      <!-- table表格 -->
      <el-table
        :data="tableData"
        style="width: 100%"
      >
        <div
          v-show="(!tableData || tableData.length <= 0) && !loading && !searchkey"
          slot="empty"
        >
          <img
            src="@/icons/pic-kong@2x.png"
            alt="img"
            style="margin-top: 20px;width: 25%;height: 25%;"
          >
          <p
            style="
                      margin-top: -20px;
                      padding-bottom: 0px;
                      "
          >这里空空如也</p>
        </div>
        <el-card
          v-show="(!tableData || tableData.length <= 0) && !loading && searchkey"
          slot="empty"
          class="table-empty-box"
          shadow="never"
        >
          <empty></empty>
        </el-card>

        <el-table-column
          type="index"
          label="序号"
          width="80"
        >
        </el-table-column>
        <el-table-column
          prop="id"
          label="车型编号"
          width="200"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="车辆类型"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="num"
          label="车型数量"
          width="100"
        >
        </el-table-column>
        <el-table-column
          prop="allowableLoad"
          label="应载重量（吨）"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="allowableVolume"
          label="应载体积（立方米）"
          width="160"
        >
        </el-table-column>
        <el-table-column
          prop="measureLong"
          label="长（米）"
        >
        </el-table-column>
        <el-table-column
          prop="measureWidth"
          label="宽（米）"
        >
        </el-table-column>
        <el-table-column
          prop="measureHigh"
          label="高（米）"
        >
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="120"
        >
          <template #default="{row}">
            <el-button
              type="text"
              size="small"
              @click="editCarInfo(row.id)"
            >编辑</el-button>
            <el-button
              type="text"
              style="color: red;"
              size="small"
              @click="del(row.id)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="block">
        <el-pagination
          :page-sizes="[10, 20, 30, 40]"
          :page-size="formTabe.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </div>
    </div>

    <!-- 弹窗 子组件 -->
    <addCarModel
      ref="openDialog"
      @getList="getTableList"
    ></addCarModel>
  </div>
</template>
<script>
import { getCarModelPageApi, delCarModelApi } from '@/api/carModel'
import addCarModel from './components/car-models-add.vue'
export default {
  components: {
    addCarModel
  },
  data() {
    return {
      searchkey: false,
      loading: true,
      // 获取车辆类型页码数据
      formTabe: {
        allowableLoad: '', // 车型载重
        allowableVolume: '', // 车型体积
        id: null, // 车型id
        name: null, // 车辆类型名称
        page: 1, // 页码
        pageSize: 10 // 页容量
      },
      // 车型载重对应关系
      allowableLoad: [
        {
          value: 'RANGE_LEVEL_1',
          name: '<1.8（吨）'
        },
        {
          value: 'RANGE_LEVEL_2',
          name: '1.8-6（吨）'
        },
        {
          value: 'RANGE_LEVEL_3',
          name: '6-14（吨）'
        },
        {
          value: 'RANGE_LEVEL_4',
          name: '14-30（吨）'
        },
        {
          value: 'RANGE_LEVEL_5',
          name: '30-50（吨）'
        },
        {
          value: 'RANGE_LEVEL_6',
          name: '50-100（吨）'
        },
        {
          value: 'RANGE_LEVEL_7',
          name: '100>（吨）'
        }
      ],
      // 车型体积对应关系
      allowableVolume: [
        {
          value: 'RANGE_LEVEL_1',
          name: '<3（m³）'
        },
        {
          value: 'RANGE_LEVEL_2',
          name: '3-5（m³）'
        },
        {
          value: 'RANGE_LEVEL_3',
          name: '5-10（m³）'
        },
        {
          value: 'RANGE_LEVEL_4',
          name: '10-15（m³）'
        },
        {
          value: 'RANGE_LEVEL_5',
          name: '15-30（m³）'
        },
        {
          value: 'RANGE_LEVEL_6',
          name: '30-50（m³）'
        },
        {
          value: 'RANGE_LEVEL_7',
          name: '50-80（m³）'
        },
        {
          value: 'RANGE_LEVEL_8',
          name: '80-150（m³）'
        },
        {
          value: 'RANGE_LEVEL_9',
          name: '150>（m³）'
        }
      ],
      // 列表数据
      tableData: [],
      // 总页码
      total: 0
    }
  },
  created() {
    // 获取表格列表
    this.getTableList()
  },
  methods: {
    // 删除车型
    del(id) {
      this.$confirm('确定要删除此条数据吗？', '温馨提示').then(async () => {
        await delCarModelApi(id)
        this.$message.success('删除成功')
        this.getTableList()
      })
    },

    // 添加车型,打开弹窗
    addCarType() {
      this.$refs.openDialog.open()
    },
    // 编辑
    editCarInfo(id) {
      this.$refs.openDialog.editCarInfo(id)
    },

    // 重置搜索框
    reset() {
      this.formTabe = {
        allowableLoad: '',
        allowableVolume: '',
        id: null,
        name: '',
        page: 1,
        pageSize: 10
      }
      this.searchkey = false
      this.getTableList()
    },

    // 搜索车型
    search() {
      this.formTabe.page = 1
      this.searchkey = true
      this.getTableList()
    },

    // 获取表格列表
    async getTableList() {
      this.loading = true
      const { data } = await getCarModelPageApi(this.formTabe)
      console.log(data)
      this.total = +data.counts
      this.tableData = data.items
      this.loading = false
    },

    // 每页页容量
    handleSizeChange(val) {
      this.formTabe.pageSize = val
      this.getTableList()
    },

    // 页码选择
    handleCurrentChange(val) {
      this.formTabe.page = val
      this.getTableList()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.box-input{
  display: flex;
  justify-content: space-between;
  margin: 10px 50px;
  color: black;
}

.block{
  text-align: center;
  margin: 20px 0;
}
.box{
  margin: 20px;
  background: #fff;
  height: 170px;
  padding-top: 20px;
}
.table{
  background-color: #fff;
  padding: 30px;
  margin: 20px;
  height: 100%;
}
.add-btn{
  margin-bottom: 20px;
}
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
  padding-bottom: 0px;
}

.el-select {
  width: 100%;
}

.car-models ::v-deep .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}
.car-models {
  ::v-deep .el-dialog__title {
    width: 73px;
    height: 25px;
    font-size: 18px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #20232a;
    line-height: 25px;
    letter-spacing: 0px;
  }
  ::v-deep .el-dialog__body {
    text-align: center;
    padding: 40px 60px 0 30px;
  }
  .warn-img {
    width: 40px;
  }
  p {
    height: 24px;
    font-size: 16px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    color: #818693;
    line-height: 24px;
  }
}
</style>
